package
{
	import ch.six4rty.doodle.Doodle;
	import ch.six4rty.doodle.data.PollDataBuilderVO;
	import ch.six4rty.doodle.events.DoodleEvent;
	import ch.six4rty.doodle.events.OAuthEvent;
	import ch.six4rty.doodle.oauth.OAuthHelper;
	import ch.six4rty.doodle.utils.URLShortener;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import nl.demonsters.debugger.MonsterDebugger;
	
	public class doodleAPI extends Sprite
	{	
		private var doodle				:Doodle 			= Doodle.getInstance();
		
		public function doodleAPI()
		{
			MonsterDebugger.enabled							= true;
			MonsterDebugger.clearTraces();
			
			doodle.addEventListener( DoodleEvent.RESULTS_RECEIVED, result, false, 0, true );
			doodle.addEventListener( DoodleEvent.DOODLE_INITIATED, init );
			
			doodle.doodleID 			= "qz388y3vftyvse5w"; //qz388y3vftyvse5w <-live ID 6wxhnxtbxtshu86k <- test id
			doodle.serverType 			= "production";
			
			doodle.init();
		}
		
		private function init( e:Event ):void
		{			
			setUI();
		}
		
		private function setUI():void
		{
			var delSp:Sprite = new Sprite();
			delSp.graphics.beginFill(0xff0000, 1 );
			delSp.graphics.drawCircle( 20, 20, 30 );
			delSp.graphics.endFill();
			addChild( delSp );
			delSp.addEventListener( MouseEvent.CLICK, testFunction, false, 0, true );
		}
		
		private function testFunction( e:MouseEvent ):void
		{
			/*var pd:PollDataBuilderVO = new PollDataBuilderVO();
			pd._type = "TEXT";
			pd._levels = "2";
			pd._hidden = "false";
			pd._title = "FlashTechnolgy 101";
			pd._description = "I would like to find out what you like to do most";
			pd._options = ["AS3", "AIR", "FLEX", "FLASH"];
			pd._initiator = "Tiago Dias";
			pd._initiatorEmail = "tiago.dias@bluewin.ch";
			
			doodle.putPoll( pd );*/
			
			doodle.requestByID();
			//doodle.postParticipant( "max", [0,1,0,0] );
			//doodle.deleteParticipant( "77999742" );
			//doodle.deleteComment( "6172230" );
			//doodle.postComment( "Tiago Dias", "Hallo Doodle, bald gibts ein AS3 client" );
		}
		
		public function result(e:DoodleEvent):void
		{
			var responseXML:XML;
			responseXML = new XML(e.data);
		}
	}
}